var express = require('express');
var app = express();
var cors=require('cors');

var mysql = require('mysql');
//配置模块
var settings = require('./settings');
//连接数据库
var connection = mysql.createConnection(settings.db);
connection.connect();

var selectSQL = 'select * from `lol`';

var arr = [];
connection.query(selectSQL, function(err, rows) {
    if (err) throw err;
    // for (var i = 0; i < rows.length; i++) {
    //     arr[i] = rows[i].id+" "+rows[i].name+" "+rows[i].alexa+" "+rows[i].country;
    //     // arr[i] = rows[i].name;
    //     // arr[i] = rows[i].alexa;
    //     // arr[i] = rows[i].country;
    //把搜索值输出
    app.get('/', function(req, res) {
        res.send(rows);
    });


});
//关闭连接
connection.end();
app.listen(3000);
app.use(cors());
console.log("监听")